package 面试.美团;

import java.util.Scanner;

/**
 * @author : K k
 * @date : 10:01 2020/9/13
 */
public class 美团1 {

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        //n行 m列
        int n= in.nextInt();
        int m= in.nextInt();
        int[][] matrix=new int[n][m];

        for(int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                matrix[i][j]=in.nextInt();
            }
        }
        //判断0次的情况
        boolean flag=true;
        for (int i=0;i<m;i++){
            if (matrix[0][i]==matrix[n-1][i]){
                continue;
            }else {
                for(int k=0;k<n;k++){
                    for (int j=0;j<m;j++){
                        if (j==m-1){
                            System.out.print(matrix[k][j]+"\n");
                        }else{
                            System.out.print(matrix[k][j]);
                        }
                    }
                }
                flag=false;
                break;
            }
        }

        if (flag) {
            //三指针记录索引
            int index = n / 2; //n一定是偶数
            int high = 0, low = index;
            while (index > 0) {
                if (matrix[high][0] == matrix[low][0]) {
                    int i;
                    while (high < low) {
                        for (i = 0; i < m; i++) {
                            if (matrix[high][i] == matrix[low][i]) {
                                continue;
                            } else {
                                break;
                            }
                        }
                        if (i == m) {
                            high++;
                            low--;
                        } else {
                            break;
                        }
                    }
                } else {
                    break;
                }
                index /= 2;
                high = 0;
                low = index;
            }
            int[][] newMatrix = new int[index + 1][m];
            for (int i = 0; i < index; i++) {
                for (int j = 0; j < m; j++) {
                    newMatrix[i][j] = matrix[i][j];
                    if (j == m - 1) {
                        System.out.print(newMatrix[i][j] + "\n");
                    } else {
                        System.out.print(newMatrix[i][j]);
                    }
                }
            }

        }
    }
}
